package com.drought.rained.ui.activity;

import android.view.View;
import android.webkit.WebView;
import android.widget.CheckBox;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.drought.rained.BuildConfig;
import com.drought.rained.LJApplication;
import com.drought.rained.R;
import com.drought.rained.base.BaseTitleActivity;
import com.drought.rained.business.RouterMapLJ;
import com.drought.rained.cache.AcacheKeysLJ;
import com.drought.rained.cache.AcacheLJ;
import com.drought.rained.network.UrlsLJ;
import com.drought.rained.utils.ToastUtilsLJ;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import crossoverone.statuslib.StatusUtil;

public class StatementActivity extends BaseTitleActivity{

    @BindView(R.id.web_view)
    WebView mWebView;
    @BindView(R.id.check_agreement)
    CheckBox checkAgreement;
    @BindView(R.id.tv_agreement)
    TextView tvAgreement;

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
    }

    @Override
    protected void onUIReady() {
        StatusUtil.setSystemStatus(this, true, false);

        tvAgreement.setText(String.format(getStringResource(R.string.privacy_agreement_has_read),
                getStringResource(R.string.app_name)));

        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setDefaultTextEncodingName("utf-8") ;
        mWebView.setBackgroundColor(0); // 设置背景色
        mWebView.loadUrl(UrlsLJ.PRIVACY_AGREEMENT_AGREEMENT_URL);
        mWebView.setVisibility(View.VISIBLE); // 加载完之后进行设置显示，以免加载时初始化效果不好看
    }

    @Override
    protected int getContentResId() {
        return R.layout.activity_statement_1;
    }

    @OnClick({R.id.tv_agreement, R.id.btn_ok})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_agreement:
                if (!checkAgreement.isChecked())
                checkAgreement.setChecked(true);
                break;
            case R.id.btn_ok:
                if (checkAgreement.isChecked()) {
                    ARouter.getInstance().build(RouterMapLJ.MAIN_ACTIVITY_PAGE).navigation();
                    finish();
                } else {
                    ToastUtilsLJ.showShort(StatementActivity.this, R.string.privacy_agreement_not_read);
                }
                break;
        }
    }

}
